<?php
namespace app\admin\controller;

class Role extends Admin
{

	protected $noNeedLogin = [];
	protected $noNeedAuth = ['*'];

	public function index()
	{
		if ( $this->request->isAjax() ){
		if($this->request->has('keyword','post')){
				$keyword = $this->request->post('keyword');
				$where = [];
			}else{
				$where = [];
			}
			return $this->service->getTableList($where);
		}
		return $this->fetch();
	}
	
	public function create()
	{
		if ( $this->request->isPost() ){
			return $this->service->create();
		}
		return $this->fetch();
	}
	
	public function update($id=null)
	{
		if ( $this->request->isPost() ){
			$this->service->update();
		}
		
		$info = $this->service->getModel()->with(['permession'])->find($id);
		$info->permessionIds = json_encode(array_column($info->permession->toArray(), 'permession_id'));
		$this->assign('info', $info);
		return $this->fetch();
	}
	
	public function delete(){
		return $this->service->delete();
	}
	
}
